<template>
    <div class="iosAddBook">
      <el-dialog append-to-body  :before-close="cancel" :visible="dialogVisible" width="600px">
        <template slot="title">
            添加证书
        </template>
        <el-form :model="form" ref="form" :rules="rules" label-width="140px">
            <el-form-item prop="bundleId" label="bundleID：" :rules="rules.bundleId">
                <el-input type="input"  v-model.trim="form.bundleId" maxlength="60"></el-input>
            </el-form-item>
            <el-form-item prop="certificate" label="证书名称：" :rules="rules.certificate">
                <el-input type="input"  v-model.trim="form.certificate" maxlength="45"></el-input>
            </el-form-item>
            <el-form-item prop="version" label="版本号：" :rules="rules.version">
                <el-input type="input"  v-model.trim="form.version" maxlength="45"></el-input>
            </el-form-item>

            <el-form-item prop="type" label="平台：">
              <!-- <el-upload
                ref="plistUpload"
                size="small"
                type="primary"
                :action="iosUploadApi"
                :on-success="ipaSuccess"
                :on-error="ipaError"
              >
                <el-button size="small" type="primary" style="display:inline-block" class="small">上传</el-button>

              </el-upload> -->
              <el-radio-group v-model="form.type">
                <el-radio :label="0">娱乐</el-radio>
                <el-radio :label="1">体育</el-radio>
                <el-radio :label="2">代理</el-radio>
            </el-radio-group>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="handleSubmit">确 定</el-button>
          </div>

      </el-dialog>
    </div>
  </template>

<script>
// import Cookies from 'js-cookie';
import { form } from '@/build';
import { systemIpaAdd } from '@/services/api/system';

export default {

  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    limit: {
      type: Number,
      default: 1,
    },
  },
  mixins: [form],

  data() {
    return {
      form: {
        bundleId: undefined,
        certificate: undefined,
        type: 0,
      },
      // iosUploadApi: `${api.UPLOAD_PIC}?token=${Cookies.get(consts.CACHE_TOKEN)}&uid=${Cookies.get(consts.CACHE_UID)}`,
      rules: {
        bundleId: [
          { required: true, message: '请填写bundleID', trigger: 'blur' },
        ],
        version: [
          { required: true, message: '请填写当前要发包的版本号', trigger: 'blur' },
        ],
        certificate: [
          { required: true, message: '请填写证书名称', trigger: ['blur', 'change'] },
        ],
      },

    };
  },
  methods: {
    cancel() {
      this.resetForm('form');
      this.$emit('cancel');
    },
    handleSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.doSave({ action: 'saveForm' });
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  mounted() {
    this.bindSave(systemIpaAdd, 'saveForm', 'form', {
      successMessage: '保存成功',
      afterSuccess: ([result, data]) => {
        if (result) {
          this.$parent.gridSearch();
          this.cancel();
        }
        return data;
      },
    });
  },
};
</script>

  <style scoped lang="scss">
 /deep/  .el-form-item__content>div{display: inline-block;margin-right:30px;}
  </style>
